import type { NamedSlotTemplates } from "@lib/Slot";
import type { UnionClassType } from "@lib/types";
import type { JSXElement, JSX, Component } from "solid-js";

export type VariantsType =
    | "primary"
    | "secondary"
    | "success"
    | "danger"
    | "warning"
    | "info"
    | "light"
    | "dark";


export interface TableProps<T> {
    datas?: T[];
    selected?: T[];
    columns?: TableColumnProps<T>[];
    variants?: VariantsType;
    borderVariants?: VariantsType;
    border?: "bordered" | "borderless";
    striped?: "striped" | "striped-columns";
    hover?: boolean;
    size?: "sm";
    groupDivider?: boolean;
    caption?: string | JSXElement;
    responsive?: boolean;
    rowKey?: Exclude<keyof T, symbol | number> | string | ((data: T) => string);
    classList?: JSX.CustomAttributes<any>["classList"];
    tableClassList?: UnionClassType
    fixedHeader?: boolean;
    style?: JSX.CSSProperties;
    nowrap?: boolean;
    captionTop?: boolean;
    captionHeight?: number;
    emptyContent?: JSXElement
}

export interface TableHeaderProps<T>
    extends JSX.HTMLAttributes<HTMLTableCellElement> {
    columns?: TableColumnProps<T>[];
    fixed?: boolean;
}

export interface TableColumnProps<T> {
    type?: "index" | "selection";
    name?: Exclude<keyof T, symbol | number> | string;
    label?: JSXElement;
    children?: (data: T, column: TableColumnProps<T>, index: number) => JSXElement;
    verticalAlign?: "middle" | "top" | "bottom";
    align?: AlignType;
    headerAlign?: AlignType;
    style?: JSX.CSSProperties;
    classList?: JSX.HTMLAttributes<HTMLElement>["classList"];
    /** 固定列 */
    fixed?: "left" | "right";
    width?: number | string;
    tooltip?: boolean;
    footer?: (datas: T[], name: string) => JSXElement | JSXElement;
}


export interface TableCellProps<T>
    extends JSX.HTMLAttributes<HTMLTableCellElement> {
    data?: T;
    column?: TableColumnProps<T>;
    columnIndex: number;
    rowIndex: number;
}


export interface TableEvents<T> {
    onSelect?: (datas?: T[]) => void;
}

export interface TableRef<T> {
    clearSelection: () => void;
}

export interface TableSlots extends NamedSlotTemplates {
    header?: Component<TableHeaderProps<any>>;
    body?: Component<TableBodyProps<any>>;
    caption?: Component<TableCaptionProps>;
    footer?: Component<TableFooterProps<any>>;
}


export interface TableFooterProps<T> extends JSX.CustomAttributes<any> {
    columns?: TableColumnProps<T>[];
    datas?: T[];
    style?: JSX.CSSProperties;
}


export interface TableRowProps<T> {
    data?: T;
    columns?: TableColumnProps<T>[];
    index: number;
}


export interface TableCaptionProps
    extends JSX.CustomAttributes<HTMLTableCaptionElement>,
    JSX.HTMLAttributes<HTMLTableCaptionElement> { }


export type Indexed<T> = T & {
    __index__: number;
};


export interface TableBodyProps<T> extends JSX.CustomAttributes<any> {
    columns?: TableColumnProps<T>[];
    datas?: T[];
    emptyContent?: JSXElement
}

export type AlignType = "start" | "center" | "end";
